package com.ocean.framework.config;
import com.ocean.common.utils.YamlUtil;
import com.ocean.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 映射访问路径
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private ISysConfigService configService;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //归档服务器路径是 win 还是 linux
        String archive = (String) YamlUtil.loadYaml("sysConfig.yaml").get("archive");
        if(archive.equals("win")) {
            String pDir = configService.selectConfigByKey("ylwin");
            String pDiryl = configService.selectConfigByKey("ncylwinys");
            System.out.println("映射预览地址"+pDir);
            System.out.println("映射预览地址nc"+pDiryl);
            // 将/files/**路径映射到本地的/data/files文件夹
            registry.addResourceHandler("/cloud/**").addResourceLocations(pDir);//win中映射 kkfileview 预览文件地址
            registry.addResourceHandler("/cloudyl/**").addResourceLocations(pDiryl);//win中映射nc文件预览生成的png地址

        }else{
            String pDir = configService.selectConfigByKey("yllinux");
            String pDiryl = configService.selectConfigByKey("ncyllinuxys");
            System.out.println("映射预览地址"+pDir);
            System.out.println("映射预览地址nc"+pDiryl);
            registry.addResourceHandler("/cloud/**").addResourceLocations(pDir);//linux中映射 kkfileview 预览文件地址
            registry.addResourceHandler("/cloudyl/**").addResourceLocations(pDiryl);//linux中映射nc文件预览生成的png地址
        }
    }
}
